﻿using Com.Aote.ObjectTools;
using System;
using System.Json;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Com.Aote.Pages
{
    public partial class 大屏显示 : UserControl
	{
        PagedList list = new PagedList();
        ObjectList userlists = new ObjectList();

		public 大屏显示()
		{
			// Required to initialize variables
			InitializeComponent();
            DispatcherTimer timer = new DispatcherTimer();
            //设置间隔1秒
            timer.Interval = new TimeSpan(0, 0, 3);
            //创建事件处理
            timer.Tick -= timer_Tick;
            timer.Tick += new EventHandler(timer_Tick);
            //开始计时
            timer.Start();
		}

        public void change(object sender, RoutedEventArgs e)
        {
            bigscreen.Visibility = Visibility.Collapsed;
            bigscreen1.Visibility = Visibility.Collapsed;
        }
        
        void timer_Tick(object sender, EventArgs e)
        {
            // 取消显示线路状态 
            //dansearchbutton_Click();
        }

        #region 查询按钮处理过程
        //private void dansearchbutton_Click()
        //{
            
        //    String uil = "";
        //    // 调用服务
        //    WebClientInfo wci = Application.Current.Resources["Linestatus"] as WebClientInfo;
        //    string uri = wci.BaseAddress + uil + ""; //?uuid=" + System.Guid.NewGuid().ToString();
        //    WebClient client = new WebClient();
        //    client.DownloadStringCompleted += dansearch_DownloadStringCompleted;
        //    client.DownloadStringAsync(new Uri(uri));



        //}

        //void dansearch_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        //{
        //    userlists = users.ItemsSource as ObjectList;
        //    //有错误
        //    if (e.Error != null)
        //    {
        //        MessageBox.Show(e.Error.Message);
        //    }
        //    else
        //    {
        //        //Linestatus.Text = e.Result;
        //        //把数据转换成JSON
        //        String str = e.Result.Substring(1, e.Result.Length - 2).Replace("\\", "");
        //        JsonObject obj = JsonValue.Parse(str) as JsonObject;
        //        JsonArray items = obj["CHTYPE_USER"] as JsonArray;

        //        daninfos.ItemsSource = list;
        //        if (list.Size != 0) {
        //            list.Clear();
        //            Linestatus.Text="";
        //            Linestatus2.Text="";
        //            Linestatus3.Text="";
        //            Linestatus4.Text = "";
        //        }
        //        int i = 0;
        //        foreach (JsonObject json in items)
        //        {
        //            GeneralObject go = new GeneralObject();
        //            if (null != json["gonghao"] && !"".Equals(json["gonghao"]) && !"99999".Equals(json["gonghao"]))
        //            {                    
        //                try
        //                {
        //                    go.EntityType = "t_";
        //                    go.SetPropertyValue("number", json["number"], false);//用户编号
        //                    go.SetPropertyValue("gonghao", json["gonghao"], false);//用户编号
        //                    go.SetPropertyValue("status", json["status"], false);//用户编号
        //                    list.Add(go);
        //                }                       
        //                catch (Exception ex)
        //                {
        //                    MessageBox.Show(ex.Message);
        //                    return;
        //                }
        //                if (i >= 0 && i <= 1) {
        //                    if ("".Equals(Linestatus.Text))
        //                        Linestatus.Text = "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                    else
        //                        Linestatus.Text = Linestatus.Text + "      " + "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                }
        //                if (i >= 2 && i <= 3) {
        //                    if ("".Equals(Linestatus2.Text))
        //                        Linestatus2.Text = "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                    else
        //                        Linestatus2.Text = Linestatus2.Text + "      " + "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                }
        //                if (i >= 4 && i <= 5) {
        //                    if ("".Equals(Linestatus3.Text))
        //                        Linestatus3.Text = "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                    else
        //                        Linestatus3.Text = Linestatus3.Text + "      " + "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                }
        //                if (i >= 6 && i <= 7) {
        //                    if ("".Equals(Linestatus4.Text))
        //                        Linestatus4.Text = "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                    else
        //                        Linestatus4.Text = Linestatus4.Text + "      " + "话务员：" + getName(userlists, (String)go.GetPropertyValue("gonghao")) + "   " + (String)go.GetPropertyValue("status");
        //                }
        //                i++;
        //            }
        //        }
        //    }
        //}

        #endregion

        String getName(ObjectList users,string gonghao)
        {
            foreach (GeneralObject go in users)
            {
                if (go.GetPropertyValue("gonghao") != null && !"".Equals(go.GetPropertyValue("gonghao")) && ((String)go.GetPropertyValue("gonghao")).Equals(gonghao))
                {
                    String name = (String)go.GetPropertyValue("name");
                    if (name.Length == 2)
                        name = "  " + name;
                    if (name.Length == 3)
                        name = " " + name;
                    return name;
                }               
            }
            return "";
        }
	}
}